<%@ page language="java" contentType="text/html; charset=UTF-8" 
 pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt"  uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ include file="index.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta charset="utf-8">
	<!-- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="Bookmark" href="favicon.ico" >
    <link rel="Shortcut Icon" href="favicon.ico" /> -->
    <title>主页</title>
    <meta name="keywords" content="耶回收">
    <meta name="description" content="耶回收">
</head>
<style type="text/css">
.input-text{width:130px;height:30px;}
</style>
<body>
<!--_表格--开始-->
<section class="Hui-article-box">
    <nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页
        <span class="c-gray en">&gt;</span>
        商品管理
        <span class="c-gray en">&gt;</span>
        商品分类
        <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a>
    </nav>
    <div class="Hui-article">
        <article class="cl pd-20">
            <div class="text-c">
				<!-- 按分类，品牌，商品名称搜索  select-box inline-->
				<form action="content-1_5" method="POST">
				<span class="select-box inline">
				<select class="select" name="classify" style="width:120px;" id="classifyselect" onchange="getbrandByid()">
					<option value="">请选择</option>
					<c:forEach items="${classifylist }" var="classify">
					<option value="${classify.cid }" <c:if test="${ba.cid==classify.cid}">selected="selected"</c:if>>${classify.classifyname }</option>
					</c:forEach>
				</select>
				</span>
				<span class="select-box inline">
				<select class="select" name="brand" id="brandselect" style="width:120px;">
					<option value="">请选择</option>
					<c:forEach items="${brandlist }" var="brand">
					<option value="${brand.pid }" <c:if test="${ba.pid==brand.pid}">selected="selected"</c:if>>${brand.brandname }</option>
					</c:forEach>
				</select>
				</span>
				<span class="inline">
				<input type="text" name="model"  value="${ba.model}"  class="input-text"/></span>
				<button name="" id="searchitem" class="btn btn-success" type="submit"><i class="Hui-iconfont">&#xe665;</i>搜索</button>
				</form>
            <div class="cl pd-5 bg-1 bk-gray mt-20">
				<span class="l">
				<shiro:hasPermission name="commodity"><a class="btn btn-primary radius" data-title="添加型号" href="addclassify"><i class="Hui-iconfont">&#xe600;</i>添加型号</a></shiro:hasPermission>
				</span>
                <!-- <span class="r">共有数据：<strong></strong> 条</span> -->
            </div>   
                <table class="table table-border table-bordered table-bg table-hover table-sort">
                    <thead>
                    <tr class="text-c">
                    
                        <th width="30">id</th>
                        <th width="75">商品分类</th>
                         <th width="60">商品品牌</th>
                          <th width="60">商品型号</th>
                        <shiro:hasPermission name="commodity"><th width="120">操作</th></shiro:hasPermission>
                    </tr>
                    </thead>
                    <tbody id="tb">
                      <c:forEach items="${pageinfo.list}" var="cbm" varStatus="status">
                     <tr class="text-c">
                        <td  width="30">${cbm.mid}</td>
                        <td  width="30">${cbm.classifyname}</td>
                        <td  width="60">${cbm.brandname }</td>
                        <td  width="60">${cbm.model }</td>
                        <shiro:hasPermission name="commodity"><td class="f-14 td-manage">
                       <a style="text-decoration:none" class="ml-5" onclick="backitem_del(this,${cbm.mid })" href="javascript:;" title="删除"><i class="Hui-iconfont">&#xe6e2;</i></a></td></shiro:hasPermission>
                    </tr>
                    </c:forEach>
                    </tbody>
                </table>
                         <strong>一共${pageinfo.pages}页</strong>
                        <strong>当前页${pageinfo.pageNum}</strong>
                 <span class="layui-breadcrumb">
                 <c:if test="${pageinfo.pageNum>1}"><a href="content-1_5?npage=1&classify=${ba.cid}&model=${ba.model}&brand=${ba.pid}">第一页</a></c:if>
                 <c:if test="${pageinfo.pageNum==1}"><a href="javascript:void(0)">第一页</a></c:if>
                 <c:if test="${pageinfo.pageNum==1}"><a href="javascript:void(0)">上一页</a></c:if>
                 <c:if test="${pageinfo.pageNum>1}"><a href="content-1_5?npage=${pageinfo.prePage}&classify=${ba.cid}&model=${ba.model}&brand=${ba.pid}">上一页</a></c:if>
                 <c:if test="${pageinfo.pageNum<pageinfo.pages }"><a href="content-1_5?npage=${pageinfo.nextPage}&classify=${ba.cid }&model=${ba.model}&brand=${ba.pid}">下一页</a></c:if>
                 <c:if test="${pageinfo.pageNum==pageinfo.pages }"><a href="javascript:void(0)">下一页</a></c:if> 
                 <c:if test="${pageinfo.pageNum==pageinfo.pages}">  <a href="javascript:void(0)">最后一页</a></c:if>
                 <c:if test="${pageinfo.pageNum<pageinfo.pages}"><a href="content-1_5?npage=${pageinfo.lastPage}&classify=${ba.cid }&model=${ba.model}&brand=${ba.pid}">最后一页</a></c:if>
             </span>
         </article>
        </div>
  </section>
<!-- 网页消息提示框 -->

<script type="text/javascript">
    $('.table-sort').dataTable({
        "aaSorting": [[ 1, "desc" ]],//默认第几个排序
        "bStateSave": true,//状态保存
        "aoColumnDefs": [
            //{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
            {"orderable":false,"aTargets":[0,8]}// 不参与排序的列
        ]
    });

 
    /*二级联动菜单*/
    
     function getbrandByid (){
    	var cid =$("#classifyselect").val();
    	
    	$.ajax({
            type: 'POST',
            url: 'getbrandByid',
            data:{"cid":cid},
            dataType: 'json',
            success: function(data){
            	
            	$("#brandselect").empty();
            	for(var i=0;i<data.brands.length;i++){
            	$("#brandselect").append("<option value="+data.brands[i].pid+">"+data.brands[i].brandname+"</option>");
            	}              	
            },
            error:function(data) {
                console.log(data.msg);
            },
        });
    	
    }
 
    /* 编辑商品 */
    function backitem_edit(title,url,id,w,h){
        var index = layer.open({
            type: 2,
            title: title,
            content: url
        });
       
        
    }
    
    
    layer.open({
		type: 2,
		area: [w+'px', h +'px'],
		fix: false, //不固定
		maxmin: true,
		shade:0.4,
		title: title,
		content: url
		 
	});  
    
    /*查看商品详情*/
    function backitem_get(title,url){
        var index = layer.open({
            type: 2,
            anim:3,
            title: title,
            area: [650+'px', 600 +'px'],
            shade:0.3,
            content:url
           
        });
        
    }
    
  
   /*xinghao删除*/
   function backitem_del(obj,mid){
       layer.confirm('确认要删除吗？',{ btn: ["确定","取消"] },function(index){
          
    	   
    	   $.ajax({
               type:"POST",
               url:"checkmodelExsitItem",//检测型号下面 有没有商品 如果没有可以删除 否则不能删除
               data:{"mid":mid},
               dataType: "json",
               success: function(rs){
            	  if(rs){
            	   $.ajax({
                       type:"POST",
                       url:"deleteModels",
                       data:{"mid":mid},
                       dataType: "json",
                       success: function(data){
                    	 layer.close(index);
                         $(obj).parents("tr").remove();
                         layer.msg("删除成功！");
                       //window.location.href = window.location.href;                	
                       },
                       error:function(data) {
                           layer.msg("删除失败");
                       },
               });  
            	   
               }else{
            	   
            	   layer.msg("该型号存在商品不能删除");
               }             	
              
    	   }
              
           });
       });
 	  
   }



   
   
   
   
    
   
   
    
    
    /*商品上线*/
    function article_shenqing(obj,id){
        $(obj).parents("tr").find(".td-status").html('<span class="label label-default radius">待审核</span>');
        $(obj).parents("tr").find(".td-manage").html("");
        layer.msg('已提交申请，耐心等待审核!', {icon: 1,time:2000});
    }
</script>
</body>
</html>